package Demo10;
/*
java------------小程序；

servlet---------服务器的小程序
 */
import Demo04.MyWin;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class AppletDemo  extends JApplet  implements MouseListener , MouseMotionListener {

    private int x1,y1,x2,y2;

    //监听
    public AppletDemo(){
        this.addMouseListener(this);
        this.addMouseMotionListener(this);
        //左     中       右
        //1       2        3
    }
//    @Override
//    public void init() {
////        super.init();
//        System.out.println("初始化……\n");
//    }
//
//    @Override
//    public void start() {
////        super.start();
//        System.out.println("开始……\n");
//    }
//
//    @Override
//    public void stop() {
////        super.stop();
//        System.out.println("停止……\n");
//    }
//
//    @Override
//    public void destroy() {
////        super.destroy();
//        System.out.println("销毁……\n");
//    }

    @Override
    public void paint(Graphics g) {
//        super.paint(g);
        System.out.println("绘画……\n");
        //颜色
        g.setClip((Shape) Color.red);
        //画圆
//        g.drawArc(400,400,300,300,0,360);
        //画线
//        g.drawLine(0,0,300,400);

        g.drawLine(x1,x2,y1,y2);
        x1=x2;
        y1=y2;

    }


    @Override
    public void mouseClicked(MouseEvent e) {
        //鼠标点击

    }

    @Override
    public void mousePressed(MouseEvent e) {
        //鼠标键按下去
        //区分
        if(e.getButton() == 1){
            //获取
            x1=x2=e.getX();
            //左     中       右
            //1       2        3
        }
        x2=e.getX();
        y2=e.getY();
        repaint();
//        x1=x2;
//        y1=y2;




    }

    @Override
    public void mouseReleased(MouseEvent e) {
        //鼠标离开

    }

    @Override
    public void mouseEntered(MouseEvent e) {
        //鼠标进入

    }

    @Override
    public void mouseExited(MouseEvent e) {
        //鼠标退出

    }

    @Override
    public void mouseDragged(MouseEvent e) {
        //鼠标托放（按着键）
        //区分
//        if(e.getButton() == 1){
//            System.out.println(e.getButton());///左中右----都是0；
//            //获取
//            x1=x2=e.getX();
//        }

    }

    @Override
    public void mouseMoved(MouseEvent e) {
        //鼠标移动（不按键）

    }


    public static void main(String[] args) {
        new  AppletDemo();
        new MyWin();
    }
}

